using STD.Shared.Common.Enums;
using STD.Shared.Infrastructure.Database.Providers;

namespace STD.Shared.Infrastructure.Database;

/// <summary>
/// 数据库提供者工厂
/// </summary>
public class DatabaseProviderFactory : IDatabaseProviderFactory
{
    private readonly Dictionary<string, IDatabaseProvider> _providers;
    
    public DatabaseProviderFactory()
    {
        _providers = new Dictionary<string, IDatabaseProvider>(StringComparer.OrdinalIgnoreCase)
        {
            { "PostgreSQL", new PostgreSQLProvider() },
            { "MySQL", new MySQLProvider() },
            { "SqlServer", new SqlServerProvider() },
            { "Oracle", new OracleProvider() },
            { "SQLite", new SQLiteProvider() }
        };
    }
    
    /// <summary>
    /// 创建数据库提供者
    /// </summary>
    /// <param name="databaseType">数据库类型</param>
    /// <returns>数据库提供者</returns>
    public IDatabaseProvider CreateProvider(string databaseType)
    {
        if (_providers.TryGetValue(databaseType, out var provider))
        {
            return provider;
        }
        
        throw new ArgumentException($"不支持的数据库类型: {databaseType}");
    }
    
    /// <summary>
    /// 获取所有支持的数据库类型
    /// </summary>
    /// <returns>数据库类型列表</returns>
    public IEnumerable<string> GetSupportedDatabaseTypes()
    {
        return _providers.Keys;
    }
}

/// <summary>
/// 数据库提供者工厂接口
/// </summary>
public interface IDatabaseProviderFactory
{
    /// <summary>
    /// 创建数据库提供者
    /// </summary>
    /// <param name="databaseType">数据库类型</param>
    /// <returns>数据库提供者</returns>
    IDatabaseProvider CreateProvider(string databaseType);
    
    /// <summary>
    /// 获取所有支持的数据库类型
    /// </summary>
    /// <returns>数据库类型列表</returns>
    IEnumerable<string> GetSupportedDatabaseTypes();
} 